home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / passwd+ / patBSD4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  1.0 KB  |  59 lines

  1. /*
  2.  * interface for pattern matchers
  3.  */
  4. #include "passwd.h"
  5.  
  6. /*
  7.  * set up some things on a per-system basis here
  8.  */
  9. char *re_comp();    /* compile regular expression */
  10.  
  11. /*
  12.  * global variables
  13.  */
  14. static char *pattern;        /* points to typed-in pattern */
  15.  
  16. /*
  17.  * smatch -- set up the pattern to be matched; bomb on error
  18.  */
  19. int smatch(pat)
  20. char *pat;            /* pattern to be matched */
  21. {
  22.     char buf[BUFSIZ];    /* buffer for error message */
  23.     register char *p;    /* points to any error message */
  24.  
  25.     /*
  26.      * compile the pattern
  27.      */
  28.     if ((p = re_comp(pat)) != NULL){
  29.         SPRINTF(buf, "%s: %s", pat, p);
  30.         paterr(buf);
  31.         return(1);
  32.     }
  33.     return(0);
  34. }
  35.  
  36. /*
  37.  * match -- compare a string to the compiled pattern
  38.  */
  39. match(str)
  40. char *str;            /* string to be compared */
  41. {
  42.     char buf[BUFSIZ];    /* buffer for error message */
  43.  
  44.     /*
  45.      * compare appropriately
  46.      */
  47.     switch(re_exec(str)){
  48.     case 1:            /* success */
  49.         return(1);
  50.     case 0:            /* failure */
  51.         return(0);
  52.     default:
  53.         SPRINTF(buf, "Internal error comparing \"%s\" to \"%s\"\n",
  54.                     str, pattern);
  55.         paterr(buf);
  56.     }
  57.     return(0);
  58. }
  59.